package web.controller.sys;

import com.github.pagehelper.PageInfo;
import framework.vo.L;
import framework.vo.R;
import framework.vo.ResultInfo;
import framework.vo.ResultList;
import io.swagger.annotations.*;
import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import system.dto.sys.SysStateAdd;
import system.dto.sys.SysStateQuery;
import system.dto.sys.SysStateResult;
import system.dto.sys.SysStateUpdate;
import system.entity.SysState;
import system.service.sys.SysStateService;

@RestController
@RequestMapping("/sys/state")
@Api(tags = "运行状态")
public class SysStateController {
    @Autowired
    private SysStateService sysStateService;

    @ApiOperation("添加运行状态")
    @PostMapping("/add")
    public ResultInfo<Long> add(@ModelAttribute SysStateAdd add) {
        java.util.Date now = new java.util.Date();
        SysState param = new SysState();
        BeanUtils.copyProperties(add, param);
        param.setUpdateTime(now);
        sysStateService.add(param);
        return R.ok(param.getId());
    }

    @ApiOperation("删除运行状态")
    @PostMapping("/del")
    public ResultInfo<Integer> del(@RequestParam("ids") List<Long> ids) {
        Integer deleted = sysStateService.deleteByIds(ids);
        return R.ok(deleted);
    }

    @ApiOperation("更新运行状态")
    @PostMapping("/edit")
    public ResultInfo<Integer> edit(@ModelAttribute SysStateUpdate update) {
        java.util.Date now = new java.util.Date();
        SysState param = new SysState();
        BeanUtils.copyProperties(update, param);
        param.setUpdateTime(now);
        Integer updated = sysStateService.updateBody(param);
        return R.ok(updated);
    }

    @ApiOperation("查看运行状态")
    @GetMapping("/info")
    public ResultInfo<SysStateResult> info(@RequestParam("id") Long id) {
        SysStateQuery query = new SysStateQuery();
        query.setId(id);
        SysStateResult info = sysStateService.listQueryOne(query);
        return R.ok(info);
    }

    @ApiOperation("运行状态列表")
    @GetMapping("/list")
    public ResultList<SysStateResult> list(@ModelAttribute SysStateQuery param, @RequestParam(value = "pageIndex", defaultValue = "1") Integer pageIndex, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageInfo<SysStateResult> info = sysStateService.listQuery(param, pageIndex, pageSize);
        return L.ok(info);
    }
}